﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.DetailsFiles
{
    /// <summary>
    /// 进场登记明细表
    /// </summary>
    public class ApproachDetailHander : IRequestHandler<ApproachDetailsCommand, Resqults<Approach>>
    {
        private readonly IBateRepository<Approach> approach;

        public ApproachDetailHander(IBateRepository<Approach> approach)
        {
            this.approach = approach;
        }

        public async Task<Resqults<Approach>> Handle(ApproachDetailsCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults<Approach> res = new Resqults<Approach>();
                var info =await approach.GetAll().FirstOrDefaultAsync(x=>x.ApproachNo==request.ApproachNo);
                if (info != null)
                {
                    res.objects = info;
                }
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
